importClass(android.graphics.drawable.GradientDrawable);
let view = ui.inflate(
  <vertical>
    <text>牙叔教程 简单易懂</text>
    <button id="dismiss">对话框消失</button>
  </vertical>,
  null,
  false
);
view.dismiss.click(function () {
  dialog.dismiss();
});
let dialog = dialogs.build({
  customView: view,
});
dialog.setCanceledOnTouchOutside(false); //点击dialog其它地方dismiss无效
let dialogWindow = dialog.getWindow();

setBackgroundRoundRounded(dialogWindow);

dialog.setOnKeyListener({
  onKey: function (dialog, keyCode, event) {
    if (keyCode === KeyEvent.KEYCODE_BACK) {
      toastLog("点击了返回键");
      return true;
    }
    return false;
  },
});

dialog.show();

function setBackgroundRoundRounded(view) {
  let gradientDrawable = new GradientDrawable();

  gradientDrawable.setShape(GradientDrawable.RECTANGLE);

  gradientDrawable.setColor(colors.parseColor("#c8e6c9"));

  gradientDrawable.setCornerRadius(60);

  view.setBackgroundDrawable(gradientDrawable);
}
